Skip to content

🛡️ Shield: Expand JSON roundtrip tests for all fake data payloads#724

Merged
fderuiter merged 1 commit intomainfrom
shield-expand-json-roundtrip-coverage-6732592961790310232
Mar 2, 2026
Merged

🛡️ Shield: Expand JSON roundtrip tests for all fake data payloads#724
fderuiter merged 1 commit intomainfrom
shield-expand-json-roundtrip-coverage-6732592961790310232

Conversation

@fderuiter
Copy link
Owner

🛑 Vulnerability: The test suite had incomplete validation for model serialization/deserialization. Only 3 out of 13 data generation functions in src/imednet/testing/fake_data.py were utilized in the generic JSON roundtrip tests, leaving most data models unverified against their payloads and creating a false sense of security. The fake_data module coverage sat at a low 40%.

🛡️ Defense: Expanded the test_json_roundtrip parameterized test to iterate over the remaining 10 models (Coding, Interval, Query, Record, RecordRevision, Site, Study, User, Variable, and Visit). Added explicit list-checking assertions for fake_forms_for_cache and fake_variables_for_cache.

🔬 Verification: Run pytest tests/unit/test_json_roundtrip.py to confirm the successful evaluation of all 15 scenarios.

📊 Impact: Boosts coverage in src/imednet/testing/fake_data.py from 40% to 81%, significantly bolstering confidence in the test suite and protecting models from arbitrary schema breakage.


PR created automatically by Jules for task 6732592961790310232 started by @fderuiter

Expanded the `tests/unit/test_json_roundtrip.py` parameterization to include 10 missing data models (`Coding`, `Interval`, `Query`, `Record`, `RecordRevision`, `Site`, `Study`, `User`, `Variable`, and `Visit`) using their respective `fake_data` generators. Added dedicated test scenarios for `fake_forms_for_cache` and `fake_variables_for_cache`. This effectively raises the coverage of `src/imednet/testing/fake_data.py` from 40% to 81%, ensuring data models and mock generation remain synced.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@fderuiter fderuiter marked this pull request as ready for review March 2, 2026 15:37
Copilot AI review requested due to automatic review settings March 2, 2026 15:37
@fderuiter fderuiter merged commit f496ec1 into main Mar 2, 2026
13 checks passed
@fderuiter fderuiter deleted the shield-expand-json-roundtrip-coverage-6732592961790310232 branch March 2, 2026 15:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands the JSON roundtrip test suite in tests/unit/test_json_roundtrip.py to cover all 13 fake data generators in src/imednet/testing/fake_data.py, up from only 3 previously. It also adds explicit cache-helper assertion tests for fake_forms_for_cache and fake_variables_for_cache.

Changes:

  • Extended the @pytest.mark.parametrize list in test_json_roundtrip from 3 entries (Subject, Form, Job) to 13 entries (adding Coding, Interval, Query, Record, RecordRevision, Site, Study, User, Variable, Visit).
  • Added a new standalone test test_fake_forms_for_cache verifying list size and study_key propagation.
  • Added a new standalone test test_fake_variables_for_cache verifying variable count, type, study_key, and form-property propagation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +48 to +51
assert len(forms) == 2
for form in forms:
assert isinstance(form, Form)
assert form.study_key == "TEST-1"
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test_fake_forms_for_cache test substantially duplicates test_fake_forms_for_cache_returns_forms in tests/utils/test_fake_data.py, which checks identical properties (list length, isinstance(f, Form), and study_key). Having the same functional coverage spread across two separate test files increases maintenance overhead without providing additional confidence.

Since the purpose of test_json_roundtrip.py is JSON roundtrip testing, these standalone fixture-validation tests may be better placed (or consolidated) in tests/utils/test_fake_data.py, or the new test should exercise something that the existing test does not (e.g., a full roundtrip assertion similar to test_fake_forms_for_cache_from_json).

Suggested change
assert len(forms) == 2
for form in forms:
assert isinstance(form, Form)
assert form.study_key == "TEST-1"
for form in forms:
payload = form.model_dump(by_alias=True)
roundtripped = Form.from_json(payload)
assert roundtripped == form

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants